package com.chenl.provider;

import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import io.micrometer.core.instrument.MeterRegistry;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@MapperScan(basePackages = {"com.chenl.provider.mapper","com.chenl.provider.DEMOS.Quartz.dynamicQuartz.po"})
@SpringBootApplication
@EnableFeignClients
@EnableDiscoveryClient
@ConfigurationPropertiesScan(basePackages = "com.chenl.provider.DEMOS")
//@EnableConfigurationProperties(YApiPropertiesByMap.class)
//@EnableScheduling
@Slf4j
@ComponentScan(basePackages = {"com.chenl"}) //如果项目中有@ComponentScan,可能会覆盖掉@SpringBootApplication里的？,可以手动扫包,同时加上启动类自动扫的那些
public class ProApplication {
    public static void main(String[] args) throws UnknownHostException {
        ConfigurableEnvironment env = SpringApplication.run(ProApplication.class, args).getEnvironment();
        log.info("\n----------------------------------------------------------\n\t" +
                        "Application '{}' is running! Access URLs:\n\t" +
                        "Local: \t\thttp://localhost:{}\n\t" +
                        "External: \thttp://{}:{}\n\t" +
//                        "ExternalWifi: \thttp://{}:{}\n\t" +
                        "----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                env.getProperty("server.port"),
                InetAddress.getLocalHost().getHostAddress(),
                env.getProperty("server.port")
//                WiFiManager.getWifiIp(),
//                env.getProperty("server.port")
        );
    }//本地启动只有接网线显示的是正确的,用wifi会错误显示

    //Actuator监控需要
    @Bean
    MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName){
        return (registry)->registry.config().commonTags("application",applicationName);
    }


    @Bean
    public SentinelResourceAspect sentinelResourceAspect(){
        return new SentinelResourceAspect();
    }
}
